import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CenterLearn extends StatelessWidget {
  const CenterLearn({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("center"),
        ),
        body: Container(
          height: 500,
          width: 500,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.pink),
            //设置圆角
            borderRadius: BorderRadius.circular(12),
          ),
          child: Center(
            child: Text(
              """
              Center 是align的直接继承实现;只是 [alignment :Alignment.center]
        
              void performLayout() {
                final BoxConstraints constraints = this.constraints;
                final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.infinity;
                final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.infinity;
            
                if (child != null) {
                  child!.layout(constraints.loosen(), parentUsesSize: true);
                  size = constraints.constrain(Size(
                    shrinkWrapWidth ? child!.size.width * (_widthFactor ?? 1.0) : double.infinity,
                    shrinkWrapHeight ? child!.size.height * (_heightFactor ?? 1.0) : double.infinity,
                  ));
                  alignChild();
                } else {
                  size = constraints.constrain(Size(
                    shrinkWrapWidth ? 0.0 : double.infinity,
                    shrinkWrapHeight ? 0.0 : double.infinity,
                  ));
                }
              }
              
              通过源码可以得知在无孩子节点时：
              如果 factory有或者没有任何约束限制则其大小为0;否则大小为尽肯能占满父空间（double.infinity）！！！
              如果存在子节点：
              如果有factory或者存在无约束限制,则根据子大小的×factory来设置，负责尽量占满整个空间！！！
              
               """,
              style: TextStyle(fontSize: 18.sp),
            ),
          ),
        ));
  }
}
